<template>
	<div class="b">
		<h1>我是B组件</h1>
		<h4>{{username}}</h4>
	</div>
</template>

<script>
	export default {
		name:'B',
		data() {
			return {
				username:''
			}
		},
		mounted() {
			this.$bus.$on('get-username',(value)=>{
				this.username = value
			})
		},
		beforeDestroy() {
			this.$bus.$off('get-username')
		},
	}
</script>

<style scoped>
	.b{
		background-color: yellow;
		padding: 20px;
		width: 50%;
		height: 200px;
	}
</style>